package com.cx.service.impl;

import com.cx.dto.PageInfoResult;
import com.cx.dto.room;
import com.cx.mapper.RoominfoMapper;
import com.cx.pojo.Roominfo;
import com.cx.service.RoomService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class RoomServiceImpl implements RoomService {
    @Autowired
    RoominfoMapper roominfoMapper;


    @Override
    public List<room> findRoomInfoBYHotelName(String hotelName) {
        return roominfoMapper.findRoomInfoBYHotelName(hotelName);
    }

    @Override
    public PageInfoResult<Roominfo> selectAllType(PageInfoResult pageParameter) {
        // 设置分页参数
        PageHelper.startPage(pageParameter.getCurrPage(), pageParameter.getPageSize());

        // 查询所有 注意分页工具只对PageHelper下的第一个select语句生效
        // SELECT count(0) FROM bookinfo   PageHelper分页插件帮我们调用，获取表中数据得总条数
        //  selelct 所有列 from bookinfo  limit 1,6
        List<Roominfo> roominfos = roominfoMapper.selectByExample(null);


        // PageInfo 包装查询结果
        // PageInfo是pageHelper提供得类，用于封装分页查询得数据
        PageInfo<Roominfo> pageInfo = new PageInfo<Roominfo>(roominfos);

        // 查询的当前页数据信息
        List<Roominfo> empList = pageInfo.getList();
        // 获取查询的总条数  select count(0) from bookinfo
        pageParameter.setTotalSize(pageInfo.getTotal());
        pageParameter.setDataList(empList);

        return pageParameter;
    }
}
